package com.zhu.shiro.cacheManager.memory;

import com.zhu.shiro.cacheManager.memory.CustomeCache;
import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.cache.CacheManager;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by DELL on 2015/12/30.
 */
public class CustomeCacheManager implements CacheManager{
    private Map<String, Cache> cacheMap= new ConcurrentHashMap<String, Cache>();

    private String prefix = "shiro_session:";

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    @Override
    public <K, V> Cache<K, V> getCache(String name) throws CacheException {

        Cache<K, V> cache = cacheMap.get(name);
        if(cache == null){
            cache = new CustomeCache<K, V>(prefix);
        }

        return cache;
    }
}
